package com.qianli.cashmama.trade.common.enums;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2017/7/28
 * Time: 下午4:20
 */
public enum TradeBorrowDurationEnum {
    DAY(1, "DAY", "天"),
    WEEK(2, "WEEK", "周"),
    MONTH(3, "MONTH", "月"),
    YEAR(4, "YEAR", "年");

    private int type;
    private String code;
    private String desc;

    TradeBorrowDurationEnum(int type, String code, String desc) {
        this.type = type;
        this.code = code;
        this.desc = desc;
    }

    public int getType() {
        return type;
    }

    public TradeBorrowDurationEnum setType(int type) {
        this.type = type;
        return this;
    }

    public String getCode() {
        return code;
    }

    public TradeBorrowDurationEnum setCode(String code) {
        this.code = code;
        return this;
    }

    public String getDesc() {
        return desc;
    }

    public TradeBorrowDurationEnum setDesc(String desc) {
        this.desc = desc;
        return this;
    }


    public static TradeBorrowDurationEnum convertByCode(String code) {
        TradeBorrowDurationEnum tradeBorrowDurationEnum = null;
        for (TradeBorrowDurationEnum borrowDurationEnum : TradeBorrowDurationEnum.values()) {
            if (borrowDurationEnum.getCode().equals(code)) {
                tradeBorrowDurationEnum = borrowDurationEnum;
                break;
            }
        }

        return tradeBorrowDurationEnum;
    }

    public static TradeBorrowDurationEnum convertByType(int type) {
        TradeBorrowDurationEnum tradeBorrowDurationEnum = null;
        for (TradeBorrowDurationEnum borrowDurationEnum : TradeBorrowDurationEnum.values()) {
            if (borrowDurationEnum.getType() == type) {
                tradeBorrowDurationEnum = borrowDurationEnum;
                break;
            }
        }

        return tradeBorrowDurationEnum;
    }
}
